package etrgo

import (
	"database/sql"
	"os"
	"reflect"
	"runtime"
	_ "sql"
)

var db *sql.DB

func GetMethodName(fn interface{}) string {
	//runtime.FuncForPC(*(*uintptr)(unsafe.Pointer(&fn)))
	return runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
}

func CheckErr(err error, msg string) bool {
	if err != nil {
		DeepError(3, "%s[%s].", msg, err)
		return true
	}
	return false
}

func init() {
	localDB, err := sql.Open("mysql", "root:admin1181@tcp(localhost:3306)/test?charset=utf8")
	if err != nil {
		panic(err)
	}
	db = localDB
}

func GetDB() *sql.DB {
	return db
}

func IsExists(path string) bool {
	_, err := os.Stat(path)
	if err == nil {
		return true
	}
	return os.IsExist(err)
}

/*func main(){

 	local := GetDB()
    rows, err := local.Query("SELECT * FROM authors")
    checkErr(err)

	var id int
    var email string	
    var name string

    for rows.Next() {        
        err = rows.Scan(&id, &email, &name)
        checkErr(err)
        fmt.Println(id)
        fmt.Println(email)
        fmt.Println(name)
    }
}*/
